﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using Gmis.IDAL;
using Gmis.DalFactory;

namespace Gmis.BLL
{
    /// <summary>
    /// LogUser
    /// </summary>
    public partial class LogUser
    {
        private readonly ILogUser dal = DataAccess.CreateLogUser();
        public LogUser()
        { }
        #region  Method
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public bool Add(Gmis.Model.LogUser model)
        {
            return dal.Add(model);
        }

        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(Gmis.Model.LogUser model)
        {
            return dal.Update(model);
        }

        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool Delete(string sID)
        {

            return dal.Delete(sID);
        }
        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool DeleteList(string sIDlist)
        {
            return dal.DeleteList(sIDlist);
        }

        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public Gmis.Model.LogUser GetModel(string sID)
        {

            return dal.GetModel(sID);
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(string strWhere)
        {
            return dal.GetList(strWhere);
        }
        /// <summary>
        /// 获得前几行数据
        /// </summary>
        public DataSet GetList(int Top, string strWhere, string filedOrder)
        {
            return dal.GetList(Top, strWhere, filedOrder);
        }
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public List<Gmis.Model.LogUser> GetModelList(string strWhere)
        {
            DataSet ds = dal.GetList(strWhere);
            return DataTableToList(ds.Tables[0]);
        }
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public List<Gmis.Model.LogUser> DataTableToList(DataTable dt)
        {
            List<Gmis.Model.LogUser> modelList = new List<Gmis.Model.LogUser>();
            int rowsCount = dt.Rows.Count;
            if (rowsCount > 0)
            {
                Gmis.Model.LogUser model;
                for (int n = 0; n < rowsCount; n++)
                {
                    model = new Gmis.Model.LogUser();
                    if (dt.Rows[n]["sID"] != null && dt.Rows[n]["sID"].ToString() != "")
                    {
                        model.sID = dt.Rows[n]["sID"].ToString();
                    }
                    if (dt.Rows[n]["sLoginName"] != null && dt.Rows[n]["sLoginName"].ToString() != "")
                    {
                        model.sLoginName = dt.Rows[n]["sLoginName"].ToString();
                    }
                    if (dt.Rows[n]["sName"] != null && dt.Rows[n]["sName"].ToString() != "")
                    {
                        model.sName = dt.Rows[n]["sName"].ToString();
                    }
                    if (dt.Rows[n]["sPassWord"] != null && dt.Rows[n]["sPassWord"].ToString() != "")
                    {
                        model.sPassWord = dt.Rows[n]["sPassWord"].ToString();
                    }
                    if (dt.Rows[n]["sRole"] != null && dt.Rows[n]["sRole"].ToString() != "")
                    {
                        model.sRole = dt.Rows[n]["sRole"].ToString();
                    }
                    if (dt.Rows[n]["lSex"] != null && dt.Rows[n]["lSex"].ToString() != "")
                    {
                        if ((dt.Rows[n]["lSex"].ToString() == "1") || (dt.Rows[n]["lSex"].ToString().ToLower() == "true"))
                        {
                            model.lSex = true;
                        }
                        else
                        {
                            model.lSex = false;
                        }
                    }
                    if (dt.Rows[n]["lSysFlag"] != null && dt.Rows[n]["lSysFlag"].ToString() != "")
                    {
                        if ((dt.Rows[n]["lSysFlag"].ToString() == "1") || (dt.Rows[n]["lSysFlag"].ToString().ToLower() == "true"))
                        {
                            model.lSysFlag = true;
                        }
                        else
                        {
                            model.lSysFlag = false;
                        }
                    }
                    if (dt.Rows[n]["lEnable"] != null && dt.Rows[n]["lEnable"].ToString() != "")
                    {
                        if ((dt.Rows[n]["lEnable"].ToString() == "1") || (dt.Rows[n]["lEnable"].ToString().ToLower() == "true"))
                        {
                            model.lEnable = true;
                        }
                        else
                        {
                            model.lEnable = false;
                        }
                    }
                    if (dt.Rows[n]["nIndex"] != null && dt.Rows[n]["nIndex"].ToString() != "")
                    {
                        model.nIndex = int.Parse(dt.Rows[n]["nIndex"].ToString());
                    }
                    if (dt.Rows[n]["sComment"] != null && dt.Rows[n]["sComment"].ToString() != "")
                    {
                        model.sComment = dt.Rows[n]["sComment"].ToString();
                    }
                    if (dt.Rows[n]["dCreateTime"] != null && dt.Rows[n]["dCreateTime"].ToString() != "")
                    {
                        model.dCreateTime = DateTime.Parse(dt.Rows[n]["dCreateTime"].ToString());
                    }
                    modelList.Add(model);
                }
            }
            return modelList;
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetAllList()
        {
            return GetList("");
        }

        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        //public DataSet GetList(int PageSize,int PageIndex,string strWhere)
        //{
        //return dal.GetList(PageSize,PageIndex,strWhere);
        //}

        #endregion  Method
    }
}
